<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>事件冒泡</title>

  <style>
    .outer {
      width: 300px;
      height: 300px;
      background-color: aquamarine;
      margin: 0 auto;
    }

    .center {
      width: 200px;
      height: 200px;
      background-color: chartreuse;
      margin: 0 auto;
    }

    .inner {
      width: 100px;
      height: 100px;
      background-color: cornflowerblue;
      margin: 0 auto;
    }
  </style>
</head>

<body>
  <div class="outer">
    outer
    <div class="center">
      center
      <div class="inner">inner</div>
    </div>
  </div>
  <script>
    // 获取元素节点
    var outer = document.getElementsByClassName('outer')[0];
    var center = document.getElementsByClassName('center')[0];
    var inner = document.getElementsByClassName('inner')[0];
    // console.log(outer)
    // console.log(center)
    // console.log(inner)
    outer.onclick = function () {
      console.log("点击了outer执行的");
    }
    center.onclick = function () {
      console.log("点击了center执行的");
    }
    inner.onclick = function (event) {
      // 阻止事件冒泡
      // event.stopPropagation();
      console.log("点击了inner执行的");
    }
  </script>
</body>

</html>